<template>
  <div v-loading="examloading" class="exam-con">
    <div :class="{ 'active': canprve }" class="exam-con-page prve" @click="prve"><i class="el-icon-arrow-left"/></div>
    <el-row>
      <el-col v-for="item in examList" :key="item.id" :span="8" >
        <div :class="{ 'active': item.id == examId}" class="exam-list-item" @click="selectExam(item)">
          <div class="item-title etc">{{ item.name || '' }}</div>
          <p class="item\-time">考试时长：<span>{{ item.totalTime }}分钟</span></p>
          <p class="item-score">总分：<span>{{ item.totalMark }}分</span></p>
          <p class="item-crtUser">创建人：<span>{{ item.crtUser }}</span></p>
          <p class="item-crtTime">创建时间：<span>{{ item.crtTime }}</span></p>
          <!-- <div class="item-btn"><a :href="'/html/exam/view.html?id='+item.id" target="_blank" @click="(event)=>{event.stopPropagation();}">预览</a></div> -->
        </div>
      </el-col>
      <el-col :span="8">
        <div class="exam-list-item create" @click="goCreateExam()">
          <p style="margin-top: 30px;">没有适合的考试~</p>
          <p>前往创建新课程考试</p>
        </div>
      </el-col>
    </el-row>
    <div :class="{ 'active': cannext }" class="exam-con-page next" @click="next"><i class="el-icon-arrow-right"/></div>
  </div>
</template>
<script>
// import { queryExamList } from '@/api/course/exam'
export default {
  name: 'Exam',
  props: {
    eObj: {
      type: Object,
      default: null
    },
    eId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      examloading: false,
      examList: [],
      examCheck: '',
      examListQuery: {
        page: 1,
        limit: 5
      },
      pageCount: 0,
      currentPage: 1,
      examobj: this.eObj,
      examId: this.eId
    }
  },
  computed: {
    canprve() {
      if (this.examListQuery.page === 1) {
        return false
      } else {
        return true
      }
    },
    cannext() {
      if (this.examListQuery.page < this.pageCount) {
        return true
      } else {
        return false
      }
    }
  },
  created() {
    this.getExamList()
  },
  methods: {
    goCreateExam() {
      this.$router.push({ path: '/exam/create?examType=2' })
    },
    selectExam(item) {
      this.examobj = Object.assign({}, item)
      this.examId = item.id
    },
    getExamList() {
      this.examloading = true
      const obj = {
        page: this.examListQuery.page,
        pageSize: this.examListQuery.limit,
        examType:2
      }
      return new Promise((resolve, reject) => {
        queryExamList(obj).then(response => {
          this.examloading = false
          this.examList = response.data.data.rows
          this.total = response.data.data.total
          this.pageCount = this.total % 6 === 0 ? (this.total / 6) : (parseInt(this.total / 6) + 1)
        }).catch(error => {
          this.examloading = false
          reject(error)
        })
      })
    },
    gotoPage(num) {
      if (num === 1 || num > 0 && this.pageCount && num <= this.pageCount) {
        this.examListQuery.page = num
        this.getExamList()
      }
    },
    prve() {
      var a = this.examListQuery.page
      a--
      if (a > 0) {
        this.gotoPage(a)
      }
    },
    next() {
      var a = this.examListQuery.page
      a++
      if (this.pageCount && a <= this.pageCount) {
        this.gotoPage(a)
      }
    }
  }
}
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
$mainColor: #18A5FD;
.exam-con{
  min-height: 350px;
  position: relative;
  .exam-con-add{
    height: 40px;
    line-height: 40px;
    border:1px dotted $mainColor;
    border-radius:4px;
    font-size:14px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:$mainColor;
    text-align: center;
    cursor: pointer;
    display: inline-block;
    width: 200px;
    margin-bottom: 10px;
    &:hover{
      border:1px dotted #FE5A61;
    }
  }
  .exam-con-page{
    position: absolute;
    top: 50%;
    margin-top: -40px;
    padding: 20px 5px;
    background-color: #E5E5E5;
    color: #ffffff;
    font-size: 16px;
    cursor: pointer;
    &.prve{
      left: -30px;
    }
    &.next{
      right: -19px;
    }
    &.active{
      background-color: #FE5A61;
    }
  }
  .exam-list-item{
    background-color: #ffffff;
    padding: 10px;
    margin-right: 10px;
    margin-bottom: 15px;
    box-shadow: 0 0 10px #f2f2f2;
    border-radius:4px;
    position: relative;
    min-height: 145px;
    cursor: pointer;
    &.create{
      p{
        text-align: center;
        font-size: 16px;
      }
    }
    &.active{
      box-shadow: 0 2px 10px #ecf8ff;
    }
    &.active:before{
      content: '';
      width: 3px;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      background-color: $mainColor;
      border-top-left-radius: 4px;
      border-bottom-left-radius: 4px;
    }
    .item-select-img{
      position: absolute;
      top: 0;
      right: 0;
    }
    p{
      margin: 5px 0;
      line-height: 1.5;
      font-family:PingFangSC-Regular;
      font-size: 12px;
    }
    .item-title{
      margin-bottom: 10px;
      .el-checkbox{
        font-size: 14px;
        color: #333333;
        .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
          background-color: #FE5A61;
          border-color: #FE5A61;
        }
        .el-checkbox__input.is-checked+.el-checkbox__label{
          color: #FE5A61;
        }
      }
    }
    .item-crtUser, .item-crtTime{
      font-size:12px;
      font-family:PingFangSC-Regular;
      font-weight:400;
      color:rgba(166,166,166,1);
    }
    .item\-time{
      color: #666666;
      span{
        color: $mainColor;
      }
    }
    .item-score{
      color: #666666;
    }
    .item-btns{
      display: flex;
      margin-top: 10px;
      position: relative;
      .el-button{
        color: rgb(253, 124, 59);
        font-family: PingFangSC-Medium;
        font-weight: 500;
        flex: 1;
        span{
          font-size: 14px;
          font-weight:500;
        }
      }
      &:before{
        content: "";
        position: absolute;
        top: 0;
        left: -10px;
        right: -10px;
        height: 1px;
        background-color: #E2E3E8;
      }
    }
  }
  .item-btn{
    position: absolute;
    padding: 4px 10px;
    bottom: 20px;
    right: 10px;
    color: #ffffff;
    background: $mainColor;
    border-radius: 4px;
    font-size: 12px;
  }
}
</style>

